package org.kzwl.book.controller.app;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.kzwl.comm.pojo.ResponseData;
import org.kzwl.comm.pojo.bo.interaction.InteractionBasicBO;
import org.kzwl.comm.pojo.bo.live.GetStreamUrlBO;
import org.kzwl.comm.pojo.dto.interaction.InteractionBasicDTO;
import org.kzwl.comm.pojo.dto.live.GetLiveBackDTO;
import org.kzwl.comm.pojo.dto.live.GetStreamUrlDTO;
import org.kzwl.comm.pojo.dto.live.LiveBasicDTO;
import org.kzwl.comm.utils.PagingCondition;
import org.kzwl.service.app.LiveService;
import org.kzwl.service.web.CuInteractionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/app-live")
@Api("直播")
public class LiveController {

    @Autowired
    private LiveService liveService;

    @ApiOperation(value = "查询直播",notes = "只需要填分页参数")
    @PostMapping("/queryBasic")
    public ResponseData<List<LiveBasicDTO>> queryBasic(@RequestBody PagingCondition bo){
        IPage<LiveBasicDTO> page =  liveService.queryBasic(bo);
        return new ResponseData<>(page.getRecords());
    }


    @ApiOperation(value = "获得直播推流",notes = "只填用户id")
    @PostMapping("/getPushUrl")
    public ResponseData<GetStreamUrlDTO> getPushUrl(@RequestBody GetStreamUrlBO bo){
        GetStreamUrlDTO dto = liveService.getPushUrl(bo);
        return new ResponseData<>(dto);
    }

    @ApiOperation(value = "获得直播间拉流",notes = "只填直播间id")
    @PostMapping("/getStreamUrl")
    public ResponseData<GetStreamUrlDTO> getPullUrl(@RequestBody GetStreamUrlBO bo){
        GetStreamUrlDTO dto = liveService.getPullUrl(bo);
        return new ResponseData<>(dto);
    }

    @ApiOperation(value = "停止直播",notes = "无需参数")
    @PostMapping("/stopLive")
    public ResponseData<GetStreamUrlDTO> stopLive(){
        liveService.stopLive();
        return new ResponseData<>();
    }

    @ApiOperation(value = "查询直播回放",notes = "分页参数")
    @PostMapping("/getPlayBack")
    public ResponseData<List<GetLiveBackDTO>> getPlayBack(@RequestBody PagingCondition bo){
        IPage<GetLiveBackDTO> list = liveService.getPlayBack(bo);
        return new ResponseData<>(list.getRecords());
    }

    public static void main(String[] args) {
        String a = "3/008/004/202096.pdf";
//        a= b+"11"+ a.substring(a.indexOf("/"));
        StringBuffer str=new StringBuffer(a);
        a= str.insert(a.indexOf("/"),"11").toString();
        System.out.println(a);
    }
}
